package cn.wzptsoft.tinymallbe.controller;

import cn.wzptsoft.common.utils.Result;
import cn.wzptsoft.tinymallbe.entity.Address;
import cn.wzptsoft.tinymallbe.entity.Order;
import cn.wzptsoft.tinymallbe.entity.Poster;
import cn.wzptsoft.tinymallbe.service.AddressService;
import cn.wzptsoft.tinymallbe.service.OrderService;
import cn.wzptsoft.tinymallbe.vo.OrderVO;
import com.fasterxml.jackson.core.JsonProcessingException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotBlank;
import java.util.List;
import java.util.Optional;

@RestController
@RequestMapping("order")
public class OrderController {
    @Autowired
    private OrderService orderService;

//    查询所有订单
    @GetMapping("/statusAll")
    public Result<List<Order>> statusAll(){
        List<Order> a= orderService.statusAll();
        return Result.ok(a);
    }

    //    添加订单
    @PostMapping("/add")
    public Result<Order> add(@RequestBody OrderVO obj) throws JsonProcessingException {
        Order a= orderService.add(obj);
        return Result.ok(a);
    }

    //    查规定订单
    @GetMapping("/status/{id}")
    public Result<List<Order>> statusid(
            @PathVariable(name = "id") Integer id){
        List<Order> a= orderService.statusid(id);
        return Result.ok(a);
    }

    //    确定支付
    @PostMapping("/zhifu")
    public Result<String> zhifu(Long id){
        String theme = orderService.zhifu(id);
        return Result.ok(theme);
    }

//    取消订单
@PostMapping("/quxiao")
public Result<String> quxiao(Long id){
    String theme = orderService.quxiao(id);
    return Result.ok(theme);
}
}
